﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data;
using System.Text;

public partial class MRP_BOM : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void UIServer1_DBChange(object sender, Evolutility.UIServer.DatabaseEventArgs e)
    {
        int id = e.ID;

        StringBuilder sbSQL = new StringBuilder();
        sbSQL.AppendFormat("INSERT INTO [MRP_Stock]([MaterialID],[Remark]) VALUES ({0},'系统于{1}自动添加！');", id, DateTime.Now);
        sbSQL.AppendFormat("INSERT INTO [MRP_StockCheck]([MaterialID],[Remark]) VALUES ({0},'系统于{1}自动添加！');", id, DateTime.Now);
        if (e.Action == Evolutility.UIServer.DBAction.INSERT)
        {
            Database db = DatabaseFactory.CreateDatabase("MRPSqlServer");

            MRPUtility.WriteLogForSQL(sbSQL.ToString());

            db.ExecuteNonQuery(CommandType.Text, sbSQL.ToString());
        }
    }
    protected void UIServer1_DBBeforeUpdate(object sender, Evolutility.UIServer.MRPDataUpdateEventArgs e)
    {
        int id = e.ID;
        if (id > 0)
        {
            Database db = DatabaseFactory.CreateDatabase("MRPSqlServer");
            string sSQL = string.Format("delete from MRP_Stock where MaterialID={0} and [InStore]=0 and [InTransit]=0 and [InLock]=0",id);
            MRPUtility.WriteLogForSQL(sSQL);
            db.ExecuteNonQuery(CommandType.Text, sSQL);
        }
    }
}
